/*
 * Copyright (C) 2003 BlackClaw, blackclaw@parsoma.net
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "stdafx.h"
#include "../client/DCPlusPlus.h"
#include "Resource.h"

#include "DcdmSettingsPage.h"
#include "../client/SettingsManager.h"
#include "WinUtil.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


PropPage::TextItem DcdmSettingsPage::texts[] = {
	{ IDC_TOKEN_FOR_CHEAT_STRING_TEXT, ResourceManager::SETTINGS_TOKEN_FOR_CHEAT_STRING },
	{ 0, ResourceManager::SETTINGS_AUTO_AWAY }
};


PropPage::Item DcdmSettingsPage::items[] = {
	{ IDC_TOKEN_FOR_CHEAT_STRING, SettingsManager::TOKEN_FOR_CHEAT_STRING, PropPage::T_INT },
	//Gabberworld new_svn 36 (R2 013)
	{ IDC_SILENTLINE,	SettingsManager::SILENTLINE,	PropPage::T_STR_SHOWDEFAULT },
	{ IDC_REMOVELINE,	SettingsManager::REMOVELINE,	PropPage::T_STR_SHOWDEFAULT },
	//end new_svn 36
	{ 0, 0, PropPage::T_END }
};

PropPage::ListItem DcdmSettingsPage::listItems[] = {
	{ SettingsManager::HIDE_DCDM_TAG, ResourceManager::SETTINGS_HIDE_DCDM_TAG },
	{ SettingsManager::SHOW_IPS, ResourceManager::SETTINGS_SHOW_IPS },
	{ SettingsManager::SHOW_IPS_PM, ResourceManager::SETTINGS_SHOW_IPS_PM },
	{ SettingsManager::TAB_WHOLE_NICK, ResourceManager::SETTINGS_TAB_WHOLE_NICK },
	{ SettingsManager::FREE_SLOTS_DEFAULT, ResourceManager::ONLY_FREE_SLOTS_DEFAULT },
	{ SettingsManager::SEND_REPORT_TO_PM, ResourceManager::SETTINGS_REPORT_TO_PM },
	{ SettingsManager::USE_VERSION_CHECKER, ResourceManager::SETTINGS_USE_VERSION_CHECKER },
	{ SettingsManager::USE_PM_FORMATTING_SCRIPT, ResourceManager::SETTINGS_USE_PM_FORMATTING_SCRIPT },
	//Sulan start svn124
	{ SettingsManager::ALERT_ON_CLIENT_UPDATES, ResourceManager::SETTINGS_ALERT_ON_CLIENT_UPDATES },
	//End
	// pothead starts
	{ SettingsManager::POPUNDER_ALERT, ResourceManager::SETTINGS_POPUNDER_ALERT },
	{ SettingsManager::PROTECT_FAVOURITES, ResourceManager::SETTINGS_PROTECT_FAVOURITES },
	// pothead ends
	// Flow84 starts
	{ SettingsManager::GET_USER_COUNTRY, ResourceManager::SETTINGS_SHOW_COUNTRYCODE },
	{ SettingsManager::GET_USER_COUNTRY_PM, ResourceManager::SETTINGS_SHOW_COUNTRYCODE_PM },
	// Flow84 ends
	{ SettingsManager::ONLINE_OFFLINE_PM, ResourceManager::SETTINGS_ONLINE_OFFLINE_PM },
	{ SettingsManager::USE_UPNP, ResourceManager::SETTINGS_USE_UPNP },
#if _SvnBuild
	{ SettingsManager::CRASH_ON_CONNECTED_TO_A_HUB, ResourceManager::SETTINGS_CRASH_ON_CONNECTED_TO_A_HUB },
#endif // _SvnBuild
	{ SettingsManager::REFRESH_FILELIST_ON_STARTUP, ResourceManager::REFRESH_FILELIST_ON_STARTUP },
	{ 0, ResourceManager::SETTINGS_AUTO_AWAY }
};

LRESULT DcdmSettingsPage::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{

	PropPage::translate((HWND)(*this), texts);
	PropPage::read((HWND)*this, items, listItems, GetDlgItem(IDC_LIST));
	// Do specialized reading here
	//Sulan start svn127
	WinUtil::decodeFont(SETTING(REPORT_FONT), reportFont);
	//End
	CComboBox box;
	box.Attach(GetDlgItem(IDC_TOKEN_FOR_CHEAT_STRING));
	for (int i = 0; i < Util::possibleNumberOfTokens(); i++)	{
		box.AddString(Util::numberToToken(i).c_str());
		if (settings->get(SettingsManager::TOKEN_FOR_CHEAT_STRING) == i)
			box.SetCurSel(i);
	}
	box.Detach();
	return TRUE;
}

void DcdmSettingsPage::write()
{
	PropPage::write((HWND)*this, items, listItems, GetDlgItem(IDC_LIST));
	//Sulan start svn127
	string f = WinUtil::encodeFont(reportFont);
	settings->set(SettingsManager::REPORT_FONT, f);

	CComboBox box(GetDlgItem(IDC_TOKEN_FOR_CHEAT_STRING));
	settings->set(SettingsManager::TOKEN_FOR_CHEAT_STRING, box.GetCurSel());
	box.Detach();
	//End

	// Do specialized writing here
	// settings->set(XX, YY);
}
//Sulan start svn127
LRESULT DcdmSettingsPage::onChangeFont(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	LOGFONT tmp = reportFont;
	CFontDialog d(&tmp, CF_SCREENFONTS, NULL, *this);
	if(d.DoModal() == IDOK) {
		reportFont = tmp;
	}
	return TRUE;
}
//End